<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box1 {
      width: 800px;
      height: 200px;
      background-color: skyblue;
      margin: 100px auto;
      text-align: center;
      font-size: 50px;
      line-height: 200px;
      font-weight: 700;
      position: relative;
      /* display: none; */
    }

    .box2 {
      width: 40px;
      height: 40px;
      border-radius: 20px;
      background-color: rgba(255, 255, 1, 0.1);
      text-align: center;
      font-weight: 400;
      line-height: 40px;
      font-size: 25px;
      right: 20px;
      top: 10px;
      position: absolute;
      cursor: pointer;
    }

    .box2:hover {
      background-color: rgba(255, 255, 1, 0.5);
    }
  </style>
</head>

<body>
  <div class="box1">
    我是广告
    <div class="box2">X</div>
  </div>
  <script>
    // 1.获取事件源
    const box1 = document.querySelector('.box1') // 关闭的是大盒子
    const box2 = document.querySelector('.box2')
    // 2.事件监听
    box2.addEventListener('click', function () {
      box1.style.display = 'none'
    })
  </script>
</body>

</html>